package com.dy.分类.栈队列堆.栈实现队列;

import java.util.Stack;

public class Solution {
    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(1);
        myQueue.push(2);
        myQueue.push(3);
        myQueue.push(4);
        while(!myQueue.empty()){
            System.out.println(myQueue.pop());
        }
    }
}

class MyQueue {
    Stack<Integer> data;
    Stack<Integer> tmp;

    /**
     * Initialize your data structure here.
     */
    public MyQueue() {
        data = new Stack<>();
        tmp = new Stack<>();
    }

    /**
     * Push element x to the back of queue.
     */
    public void push(int x) {

        while(!data.isEmpty()){
            tmp.add(data.pop());
        }
        tmp.push(x);
        while(!tmp.isEmpty()){
            data.push(tmp.pop());
        }
    }

    /**
     * Removes the element from in front of queue and returns that element.
     */
    public int pop() {
        return data.pop();
    }

    /**
     * Get the front element.
     */
    public int peek() {
        return data.peek();
    }

    /**
     * Returns whether the queue is empty.
     */
    public boolean empty() {
        return data.isEmpty();
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */
